import pytest

from api.LoginAPI import loginApi
import sys
import os

# 添加项目根目录到 sys.path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../../..")))


# 设置日志输出目录
@pytest.hookimpl(tryfirst=True)
def pytest_configure(config):
    log_file = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'result', 'logs', 'test.log')
    os.makedirs(os.path.dirname(log_file), exist_ok=True)
    config.option.log_file = log_file


@pytest.fixture(scope="session")  # function
def login_fixture():
    l = loginApi()
    login = l.login("************", "************@123456")
    return login.json().get("data").get("token")  # 获取token
